/*
 *    Copyright (c) 2018-2025, lengleng All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 * Redistributions of source code must retain the above copyright notice,
 * this list of conditions and the following disclaimer.
 * Redistributions in binary form must reproduce the above copyright
 * notice, this list of conditions and the following disclaimer in the
 * documentation and/or other materials provided with the distribution.
 * Neither the name of the pig4cloud.com developer nor the names of its
 * contributors may be used to endorse or promote products derived from
 * this software without specific prior written permission.
 * Author: lengleng (wangiegie@gmail.com)
 */

package com.pig4cloud.pig.generator.controller;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.pig4cloud.pig.common.core.util.R;
import com.pig4cloud.pig.common.log.annotation.SysLog;
import com.pig4cloud.pig.generator.entity.PmsSkuStock;
import com.pig4cloud.pig.generator.service.PmsSkuStockService;
import com.pig4cloud.pig.generator.utils.QiniuUtil;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;


/**
 * 商品SKU表
 *
 * @author pig code generator
 * @date 2021-07-15 12:08:22
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/pmsskustock" )
@Api(value = "pmsskustock", tags = "商品SKU表管理")
public class PmsSkuStockController {

    private final  PmsSkuStockService pmsSkuStockService;

    /**
     * 分页查询
     * @param page 分页对象
     * @param pmsSkuStock 商品SKU表
     * @return
     */
    @ApiOperation(value = "分页查询", notes = "分页查询")
    @GetMapping("/page" )
    @PreAuthorize("@pms.hasPermission('generator_pmsskustock_get')" )
    public R getPmsSkuStockPage(Page page, PmsSkuStock pmsSkuStock) {
        return R.ok(pmsSkuStockService.page(page, Wrappers.query(pmsSkuStock)));
    }


    /**
     * 通过id查询商品SKU表
     * @param id id
     * @return R
     */
    @ApiOperation(value = "通过id查询", notes = "通过id查询")
    @GetMapping("/{id}" )
    @PreAuthorize("@pms.hasPermission('generator_pmsskustock_get')" )
    public R getById(@PathVariable("id" ) Long id) {
        return R.ok(pmsSkuStockService.getById(id));
    }

    /**
     * 新增商品SKU表
     * @param pmsSkuStock 商品SKU表
     * @return R
     */
    @ApiOperation(value = "新增商品SKU表", notes = "新增商品SKU表")
    @SysLog("新增商品SKU表" )
    @PostMapping
    @PreAuthorize("@pms.hasPermission('generator_pmsskustock_add')" )
    public R save(@RequestBody PmsSkuStock pmsSkuStock) {
        return R.ok(pmsSkuStockService.save(pmsSkuStock));
    }

    /**
     * 修改商品SKU表
     * @param pmsSkuStock 商品SKU表
     * @return R
     */
    @ApiOperation(value = "修改商品SKU表", notes = "修改商品SKU表")
    @SysLog("修改商品SKU表" )
    @PutMapping
    @PreAuthorize("@pms.hasPermission('generator_pmsskustock_edit')" )
    public R updateById(@RequestBody PmsSkuStock pmsSkuStock) {
        return R.ok(pmsSkuStockService.updateById(pmsSkuStock));
    }

    /**
     * 通过id删除商品SKU表
     * @param id id
     * @return R
     */
    @ApiOperation(value = "通过id删除商品SKU表", notes = "通过id删除商品SKU表")
    @SysLog("通过id删除商品SKU表" )
    @DeleteMapping("/{id}" )
    @PreAuthorize("@pms.hasPermission('generator_pmsskustock_del')" )
    public R removeById(@PathVariable Long id) {
        return R.ok(pmsSkuStockService.removeById(id));
    }

	@ResponseBody
	@PostMapping("/uploadImg" )
	public R uploadImg(@RequestParam("file") MultipartFile image) throws IOException {
		String filename = image.getOriginalFilename();
		String s = QiniuUtil.uploadQiNiu(image.getBytes(), filename);
		return R.ok(s);
	}
}
